package com.wthink.hzgj.bus

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wthink.hzgj.data.domain.BusDispatch
import com.wthink.hzgj.service.DevService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

class PlanViewModel : ViewModel() {

    val dispatch = MutableLiveData<BusDispatch>()

    fun setBusDispatch(data: BusDispatch) {
        this.dispatch.postValue(data)
    }

    fun start() {
        viewModelScope.launch(Dispatchers.IO) {
            DevService.listenBusDispatch().collect {
                dispatch.postValue(it)
            }
        }
    }
}
